package com.edgclub.edg.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.edgclub.edg.R;
import com.edgclub.edg.activity.UserInfoOtherActivity;
import com.edgclub.edg.model.User;
import com.edgclub.edg.utils.GlideUtil.GlideUtils;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;

/**
 * EDG之星
 */
public class FindStarAdapter extends BaseAdapter {
    private Context mContext;

    private ArrayList<User> stars;

    private GlideUtils glideUtils;

    private ViewHolder holder;

    public FindStarAdapter(Context mContext) {
        this.mContext = mContext;
        glideUtils = new GlideUtils();
    }

    public ArrayList<User> getStars() {
        return stars;
    }

    public void setStars(ArrayList<User> stars) {
        this.stars = stars;
    }

    @Override
    public int getCount() {
        return stars.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        if (null == convertView) {
            convertView = LayoutInflater.from(mContext).inflate(
                    R.layout.item_find_star, null);
            holder = new ViewHolder();
            holder.user_icon = (ImageView) convertView.findViewById(R.id.user_icon);
            holder.vip = (ImageView) convertView.findViewById(R.id.vip);
            holder.tv_title = (TextView) convertView.findViewById(R.id.tv_title);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final User star = stars.get(position);
        holder.tv_title.setText(star.getNick()+"");
        glideUtils.Glidde_loadCropCircleImage(mContext,star.getLogo(), holder.user_icon);
        holder.user_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                User user = new User();
                user.setId(star.getId());
                user.setImid(star.getImid());
                user.setNick(star.getNick());
                user.setLogo(star.getLogo());
                user.setGzno(star.getGzno());
                Intent intent=new Intent(mContext, UserInfoOtherActivity.class);
                intent.putExtra("user",user);
                mContext.startActivity(intent);
                MobclickAgent.onEvent(mContext,"EC_FIND_EDG_STAR");
            }
        });

        if(null!=star.getUserAuth()){
            if ("-1".equals(star.getUserAuth().getType())){
                holder.vip.setVisibility(View.GONE);
            }
            if("0".equals(star.getUserAuth().getType())){
                holder.vip.setVisibility(View.VISIBLE);
                holder.vip.setImageResource(R.drawable.v_huan);
            }else if("1".equals(star.getUserAuth().getType())){
                holder.vip.setVisibility(View.VISIBLE);
                holder.vip.setImageResource(R.drawable.v_lan);
            }
        }else{
            holder.vip.setVisibility(View.GONE);
        }


        return convertView;
    }


    public class ViewHolder {

        public ImageView user_icon , vip;
        public TextView tv_title;
    }


}
